﻿using NLog;
using NLog.LayoutRenderers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PortCommunicate.LogEntries
{
    public enum RWType
    {
        read, write
    }

    public partial class Mediator
    {
        //静态单例，全局访问
        public static Mediator Instance { get; set; } = new Mediator();
        //获取当前Tab名称
        public static RWType? currentRWType = RWType.read;
    }

    [LayoutRenderer("currentRWType")]
    public class MediatorLayoutRenderer : LayoutRenderer
    {
        protected override void Append(StringBuilder builder, LogEventInfo logEvent)
        {
            // 获取Mediator中的currentRWType值
            if (Mediator.currentRWType.HasValue)
            {
                builder.Append(Mediator.currentRWType.Value.ToString());
            }
            else
            {
                builder.Append("unknown");
            }
        }
    }
}
